# ================================================== <<AUTO GENERATE CODE>>
# Copyright (c) 2024 HDM
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
#    this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Commercial use of this software requires explicit authorization from the
# copyright holder. For commercial licensing inquiries, please contact
# sks853@163.com or visit https://blog.csdn.net/qq_43634664
#
# Non-commercial use is permitted under the conditions outlined above.
# ================================================== <<AUTO GENERATE CODE>>

log("console" "Using CXX STANDARD ${CMAKE_CXX_STANDARD}")

INCLUDE(GenerateExportHeader)
INCLUDE(CMakePackageConfigHelpers)

# ==================================================
# turn off Qt auto-gen
# ==================================================
SET(CMAKE_AUTOMOC OFF)
SET(CMAKE_AUTORCC OFF)
SET(CMAKE_AUTOUIC OFF)
# ==================================================

# ==================================================
# properties settings
# ==================================================
SET(CMAKE_DEBUG_POSTFIX d)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/output)
#SET(CMAKE_BUILD_TYPE $<$<CONFIG:>:Undefined>$<$<NOT:$<CONFIG:>>:$<CONFIG>>)

IF (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
    SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin${_platform}/undefined")
    SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin${_platform}/undefined")
    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/bin${_platform}/undefined")
    SET(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/temp/")
    SET(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
    SET(US_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
    SET(CMAKE_ENABLE_EXPORTS ON)
ENDIF ()
# ==================================================

# ==================================================
# using latest C++ feature
# ==================================================
ADD_COMPILE_OPTIONS(/std:c++latest)
# ==================================================

# ==================================================
# enable C++ 17
# ==================================================
IF (${CMAKE_CXX_STANDARD} GREATER 14)
    IF (MSVC)
        IF (MSVC_VERSION GREATER 1900)
            SET(FLAG_CXX_VERSION_HIGHER ON)
            ADD_DEFINITIONS(-DFLAG_CXX_VERSION_HIGHER=1)
        ENDIF ()
    ELSE ()
        SET(FLAG_CXX_VERSION_HIGHER ON)
        ADD_DEFINITIONS(-DFLAG_CXX_VERSION_HIGHER=1)
    ENDIF ()
ELSE ()
    SET(FLAG_CXX_VERSION_HIGHER OFF)
    ADD_DEFINITIONS(-DFLAG_CXX_VERSION_HIGHER=0)
ENDIF ()

IF (MSVC)
    ADD_DEFINITIONS(-DFLAG_CXX_PLATFORM_WIN=1)
ELSE ()
    ADD_DEFINITIONS(-DFLAG_CXX_PLATFORM_WIN=0)
ENDIF ()
# ==================================================

# ==================================================
# enable C++ 20
# ==================================================
IF (${CMAKE_CXX_STANDARD} GREATER 20)
    IF (MSVC)
        IF (MSVC_VERSION GREATER_EQUAL 1920)
            SET(FLAG_CXX_VERSION_20 ON)
            ADD_DEFINITIONS(-DFLAG_CXX_VERSION_20=1)
        ENDIF ()
    ELSE ()
        SET(FLAG_CXX_VERSION_20 ON)
        ADD_DEFINITIONS(-DFLAG_CXX_VERSION_20=1)
    ENDIF ()
ELSE ()
    SET(FLAG_CXX_VERSION_20 OFF)
    ADD_DEFINITIONS(-DFLAG_CXX_VERSION_20=0)
ENDIF ()
# ==================================================

# ==================================================
# enable PIC if linux
# ==================================================
IF (NOT MSVC)
    SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
ENDIF()
# ==================================================
